import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { PopoverController } from '@ionic/angular';

export enum OperationType {
  MultiChat,
  AddFriend,
  Scan,
  CollectAndPay,
  Help
}

@Component({
  selector: 'app-operations-popover',
  templateUrl: './operations-popover.component.html',
  styleUrls: ['./operations-popover.component.scss'],
})
export class OperationsPopoverComponent implements OnInit {

  InnerType = OperationType;

  returnUrl: string;

  constructor(private router: Router, private popoverCtrl: PopoverController, private camera: Camera) { }

  ngOnInit() { }

  doClick(type: OperationType) {

    if (type == OperationType.Scan) {
      const options: CameraOptions = {
        quality: 100,
        destinationType: this.camera.DestinationType.FILE_URI,
        encodingType: this.camera.EncodingType.JPEG,
        mediaType: this.camera.MediaType.PICTURE
      }
      this.camera.getPicture(options).then((imageData) => {
        // imageData is either a base64 encoded string or a file URI
        // If it's base64 (DATA_URL):
        let base64Image = 'data:image/jpeg;base64,' + imageData;
      }, (err) => {
        // Handle error
      });
    } else if (type == OperationType.AddFriend) {
      this.router.navigate(['/contacts/contacts-create'], { queryParams: { returnUrl: this.returnUrl } })
    }

    this.popoverCtrl.dismiss(type);
  }
}
